import java.util.Arrays;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[][] circles = new int[n][3];
        for(int i = 0;i < n;i++){
            circles[i][0] = scanner.nextInt();
            circles[i][1] = scanner.nextInt();
            circles[i][2] = scanner.nextInt();
        }
        double[][] dist = new double[n][n];
        for(int i = 0;i < n;i++){
            for(int j = i+1;j < n;j++){
                double dx = circles[i][0]-circles[j][0];
                double dy = circles[i][1]-circles[j][1];
                double d = Math.sqrt(dx*dx+dy*dy);
                dist[i][j] = Math.max(0,d-circles[i][2]-circles[j][2]);
                dist[j][i] = dist[i][j];
            }
        }
        double[] minDist = new double[n];
        Arrays.fill(minDist,Double.POSITIVE_INFINITY);
        minDist[0] =0;
        boolean[] visited = new boolean[n];
        double total = 0;
        for(int i = 0;i <n;i++){
            int u = -1;
            for(int j = 0;j < n;j++){
                if(!visited[j] && (u == -1 || minDist[j] <minDist[u])){
                    u = j;
                }
            }
            visited[u] = true;
            total += minDist[u];
            for(int v = 0; v< n;v++){
                if(!visited[v] && dist[u][v] < minDist[v]){
                    minDist[v] = dist[u][v];
                }
            }
        }
        System.out.printf("%.2f\n",total);
    }
}